  #include "StdAfx.h"
        #include "Setup.h"

        //Configure these as you wish
        #define BREAKTIME 300000      //The amount of seconds * 1000 you want to wait in between messages
        #define HEADERSTR "ex-WoW>"   //The string to place in front of the message

        //Define and create variables
        uint32 ann_next_id = 0;

        class Announcement
        {
           public:
              void Run();
        };

        void Announcement::Run()
        {
           // Variable Defines
           char query[255];
           char display_str[255];
           string body;
           uint32 id, next_id;

           if(ann_next_id == 0)
           {
              sprintf(query, "SELECT * FROM announcer_txt ORDER BY RAND() LIMIT 1");
           } else {
              sprintf(query, "SELECT * FROM announcer_txt WHERE id = %i", ann_next_id);
           }
           QueryResult * result = WorldDatabase.Query(query);

           //Uh oh!
           if(!result)
           {
              ShowMsg("Something went wrong or there is no data to display!");
              ann_next_id = 0;
              return;
           }

           //Lets get the data, and set everyting up
           Field * fields = result->Fetch();
           id = fields[0].GetUInt32();
           body = fields[1].GetString();
           next_id = fields[2].GetUInt32();

           //We may need to set next id, and set last id
           if(next_id != 0)
              ann_next_id = next_id;
           else
              ann_next_id = 0;

           //Lets format the String to display and then display it!
           sprintf(display_str, "%s %s", HEADERSTR, body.c_str());
           sWorld.SendWorldText(display_str);

           //to prevent overscope and leaking
           WorldDatabase.FreeQueryResult(result);
        }

        void ShowMsg(char * errmsg)
        {
           char errstr[255];
           sprintf(errstr, "\nAnnouncer v2: %s", errmsg);
           sLog.outString(errstr);
        }

        void SetupAnnouncer(ScriptMgr * mgr)
        {
           Announcement Announcer;
           //If all is good, set up the timer event and lets roll!
           if(BREAKTIME >= 1000)
           {
              TimedEvent * te = TimedEvent::Allocate(&Announcer, new CallbackP0<Announcement>(&Announcer, &Announcement::Run), 1, BREAKTIME, 0);
              sWorld.event_AddEvent(te);
              ShowMsg("Announcer has been started!");
           } else {
              //Someone has their time set under 1 second. ;P
              ShowMsg("Announcer has been disabled.  Please insure you have the config set right!");
           }

        }